package com.itheima.article.mapper;

import com.itheima.article.dto.ArticleHomeDto;
import com.itheima.article.dto.ArticleVisitStreamMess;
import com.itheima.article.pojo.ApArticle;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description <p>已发布的文章信息 Mapper 接口</p>
 *
 * @version 1.0
 * @package com.itheima.article.mapper
 */
@Repository
public interface ApArticleMapper extends BaseMapper<ApArticle> {

    /**
     * app端 文章列表分页
     * @param dto
     * @param type
     * @return
     */
    List<ApArticle> findPage(ArticleHomeDto dto, int type);

    /**
     * 按发布时间，查询多少天前的文章
     * @param beginDate
     * @return
     */
    @Select("select aa.* from ap_article aa inner join ap_article_config ac on aa.id=ac.id where ac.is_down=0 and ac.is_delete=0 " +
        "and aa.publish_time>=#{beginDate}")
    List<ApArticle> selectAfterDate(String beginDate);

    /**
     * 更新文章里的数量
     * @param mess
     */
    @Update("update ap_article set views=views+#{view}, likes=likes+#{like}, collection=collection+#{collect}, comment=comment+#{comment}" +
        " where id=#{articleId}")
    void updateNumber(ArticleVisitStreamMess mess);
}
